//https://leetcode.cn/problems/target-sum/
class Solution {
    int ret;
    int pathOfSum;
    public int findTargetSumWays(int[] nums, int target) {
        dfs(nums, target, 0);
        return ret;
    }
    public void dfs(int[] nums, int target,int pos) {
        if(pos == nums.length) {
            if(pathOfSum == target) ret++;
            return;
        }
        //加
        pathOfSum += nums[pos];
        dfs(nums, target, pos + 1);
        //回溯
        pathOfSum -= nums[pos];

        //减
        pathOfSum -= nums[pos];
        dfs(nums, target, pos + 1);
        //回溯
        pathOfSum += nums[pos];
    }
}